﻿using System.Web.Mvc;
using DemoMVC.Models;
using Highcharts.Core;
using Highcharts.Core.Data.Chart;
using Highcharts.Core.Options;
using Highcharts.Core.PlotOptions;

namespace DemoMVC.Controllers
{
    public class PieChartController : Controller
    {
        public ActionResult Index()
        {
            return View(GetViewData());
        }

        private static ChartViewData GetViewData()
        {

            var chartOptions = new ChartOptions
            {
                Title = new Title("Browsers dos visitantes"),
                PlotOptions = new PlotOptionsArea
                {
                    lineColor = "#ffffff",
                    lineWidth = 1,
                    fillOpacity = 0.3
                },
                Tooltip = new ToolTip(@"Highcharts.numberFormat(this.percentage, 1) + '% ('+ Highcharts.numberFormat(this.y, 0, ',') +' milhões)'")
            };

            //Chart Data (series)
            chartOptions.Series.Add(new Serie
                                        {
                                            data = new object[] { 
                                                new object[] { "Firefox", 45 }, 
                                                new object[] { "IE", 24.8 }, 
                                                new object[] { "Chrome", 12.8 },
                                                new object[] { "Safari", 8.5 }, 
                                                new object[] { "Opera", 5.2 }, 
                                                new object[] { "Outros", 3.7 } 
                                            }
                                        });

            return new ChartViewData
            {
                ChartAreaData = chartOptions
            };
        }
    }
}
